//
//  TBPlayerViewController.swift
//  funcode
//
//  Created by Wan Jiading on 2017/2/9.
//  Copyright © 2017年 WanJiading. All rights reserved.
//

import UIKit

class TBPlayerViewController: UIViewController {
	
	var currentLengthLabel = UILabel()
	var maxLengthLabel = UILabel()
	
	
	var showView: UIView!
	
	override func viewDidLoad() {
		super.viewDidLoad()
		
		setupSubViews()
		setupPlayer()
	}
	
	private func setupPlayer() {
		
		let urlString = "http://exploiter.oss-cn-beijing.aliyuncs.com/audio/147/5p2h57q56bG85b6X5pWR5LqG_chinesestory_1484588477_1.mp3"
	
		let screenSize = UIScreen.main.bounds
		self.showView = UIView(frame: CGRect(x: 0, y: 64, width: screenSize.width, height: screenSize.height - 64))
		self.view.addSubview(self.showView)
		
		TBPlayer.shared.play(URL(string: urlString)!, self.showView)
		
	}
	
	private func setupSubViews() {
		
		self.view.backgroundColor = UIColor.white
		
		
		let x = 30
		let y = 200
		let w = 300
		let h = 50
		
		setupLabel(currentLengthLabel, "下载大小")
		currentLengthLabel.frame = CGRect(x: x, y: y, width: w, height: h)
		currentLengthLabel.sizeToFit()
		self.view.addSubview(currentLengthLabel)
		
		setupLabel(maxLengthLabel, "总大小")
		maxLengthLabel.frame = CGRect(x: x, y: Int(currentLengthLabel.frame.maxY + 20), width: w, height: h)
		maxLengthLabel.sizeToFit()
		self.view.addSubview(maxLengthLabel)
	}
	
	private func setupLabel(_ label: UILabel, _ text: String) {
		
		label.text = text
		label.font = UIFont.systemFont(ofSize: 16)
		label.textAlignment = .left
		label.textColor = UIColor.red
		label.backgroundColor = UIColor.white
		
	}
	
	override func didReceiveMemoryWarning() {
		super.didReceiveMemoryWarning()
	}
}
